#include<func.h>
typedef struct student
{
    int ID;
    char name[10];
    int score;
}stu_t,*pstu_t;
int main(int argc,char* argv[])
{
    stu_t stu[3]={{1001,"lili" ,89},{1002 ,"lilei",97},{1003, "jimmy", 100}};
    
    ARGS_CHECK(argc,3)
    int fd;
    fd=open(argv[1],O_RDWR);
    ERROR_CHECK(fd,-1,"open");
    int ret;
    ret=ftruncate(fd,atoi(argv[2]));
    ERROR_CHECK(fd,-1,"ftruncate");
    lseek(fd,0,SEEK_SET);
    char buf[100];
    for(int i=0;i<3;i++)
    {
        memset(buf,'0',sizeof(buf));
        sprintf(buf,"%d\t%s\t%d",stu[i].ID,stu[i].name,stu[i].score);
        write(fd,buf,sizeof(stu));
    } 
    lseek(fd,0,SEEK_SET);

    for(int j=0;j<3;j++)
    {
         memset(buf,'0',sizeof(buf));
        read(fd,buf,sizeof(stu));
        printf("%s\n",buf);
    }
    close(fd);
    return 0;

}